﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using CSharpWin;

namespace DoctorWorkstationManage
{
    public partial class DailyTemplateForm : SkinForm
    {
        string m_labelControlInfoText = string.Empty;

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="lastTime"></param>
        /// <param name="title"></param>
        /// <param name="isFirstDailyEmr">是否是首次病程，对于首次病程没有时间限制</param>
        public DailyTemplateForm(DateTime lastTime, string title, bool isFirstDailyEmr)
        {
            InitializeComponent();
            if (!isFirstDailyEmr)
            {
                this.label_RYDate.Text = lastTime.ToString("yyyy-MM-dd HH:mm:ss");
                m_labelControlInfoText = label_RYDate.Text;
                this.label_RYDate.Text = "病程日期不能小于 " + m_labelControlInfoText;
            }
            else
            {
                label_RYDate.Text = "";
                m_labelControlInfoText = "";
            }
            dateEdit_Date.Value = DateTime.Now.Date;
            textEdit_Name.Text = title;
        }

        public DateTime CommitDateTime
        {
            get { return DateTime.Parse(dateEdit_Date.Value.ToString("yyyy-MM-dd HH:mm:ss")); }
        }

        public string CommitTitle
        {
            get { return textEdit_Name.Text; }
        }

        private void BindBasicInfo()
        {
            //


        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (m_AllDisplayDateTime.Contains(CommitDateTime.ToString("yyyy-MM-dd HH:mm:ss")))
            {
                this.label_RYDate.Text = "病程日期已存在";
                return;
            }

            if (m_labelControlInfoText != "" && (CommitDateTime - Convert.ToDateTime(m_labelControlInfoText)).TotalMinutes < 0)
            {
                this.label_RYDate.Text = "病程日期不能小于 " + m_labelControlInfoText;
                return;
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }

        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private List<string> m_AllDisplayDateTime = new List<string>();

        /// <summary>
        /// 设置病程的所有时间
        /// </summary>
        /// <param name="node"></param>
        public void SetAllDisplayDateTime(TreeNode node)
        {
            try
            {
                string tagstring;
                if (node.Nodes.Count > 0)
                { 
                    for(int i=0;i<node.Nodes.Count;i++)
                    {
                       tagstring=(string)node.Nodes[i].Tag;
                        string[] str=tagstring.Split(';');
                        int strlength=str.Length;
                        tagstring=str[strlength-1].ToString();
                        m_AllDisplayDateTime.Add(tagstring);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
    }
}
